package com.chenfan.mcn.component.dict;

import com.chenfan.mcn.clients.privilege.PrivilegeClient;
import com.chenfan.mcn.clients.privilege.ScompanyRes;
import com.chenfan.common.extension.context.SpringContextHolder;
import com.chenfan.common.extension.dict.DictTranslator;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 我司签约主体-翻译成名称
 *
 * @author wulg
 * @date 2021-12-11
 **/
public class ContractingIdTranslator implements DictTranslator<Long, String> {

    @Override
    public String translate(Long contractingId) {
        PrivilegeClient privilegeClient = SpringContextHolder.getBean(PrivilegeClient.class);
        List<ScompanyRes> companyResList = privilegeClient.getParList().getObj();
        Map<Long, String> companyMap = companyResList.stream().collect(Collectors.toMap(k -> k.getCompanyId(), v -> v.getParentCompanyName()));
        if(companyMap.containsKey(contractingId)) {
            return companyMap.get(contractingId);
        }
        return contractingId.toString();
    }
}
